package com.ruoyi.durian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.durian.domain.LlUserOpenTaxi;
import com.ruoyi.durian.service.LlUserOpenTaxiService;
import com.ruoyi.durian.mapper.LlUserOpenTaxiMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
* @author lenovo
* @description 针对表【ll_user_open_taxi(用户代叫开关表)】的数据库操作Service实现
* @createDate 2024-08-12 10:17:38
*/
@Service
public class LlUserOpenTaxiServiceImpl extends ServiceImpl<LlUserOpenTaxiMapper, LlUserOpenTaxi>
    implements LlUserOpenTaxiService{

    @Resource
    private LlUserOpenTaxiMapper llUserOpenTaxiMapper;

    /**
     * 关闭开启朋友代叫
     *
     * @return
     */
    @Override
    @Transactional
    public AjaxResult openOrCloceTaxi(LlUserOpenTaxi llUserOpenTaxi) {
        Integer userId = SecurityUtils.getUserId().intValue();
        LambdaQueryWrapper<LlUserOpenTaxi> qw = new LambdaQueryWrapper<>();
        qw.eq(LlUserOpenTaxi::getUserId,userId);
        LlUserOpenTaxi llUserOpenTaxi1 = llUserOpenTaxiMapper.selectOne(qw);
        if (llUserOpenTaxi1 == null){
            llUserOpenTaxi1 = new LlUserOpenTaxi();
        }
        llUserOpenTaxi1.setUserId(userId);
        llUserOpenTaxi1.setIsOpen(llUserOpenTaxi.getIsOpen());
        saveOrUpdate(llUserOpenTaxi1);
        return AjaxResult.success();
    }

    /**
     *
     * @return
     */
    @Override
    public AjaxResult getRecallStatus() {

        Integer userId = SecurityUtils.getUserId().intValue();

        LambdaQueryWrapper<LlUserOpenTaxi> eq = new LambdaQueryWrapper<LlUserOpenTaxi>()
                .eq(LlUserOpenTaxi::getUserId, userId);
        return AjaxResult.success(llUserOpenTaxiMapper.selectOne(eq));
    }
}




